package com.night.administration.controller;

import com.night.administration.excepyion.AreaConflictException;
import com.night.administration.feign.AreaFeign;
import com.night.administration.feign.StudentFeign;
import com.night.administration.service.CourseManagerService;
import com.night.common.entity.PageBean;
import com.night.common.entity.ResultVo;
import com.night.common.entity.administration.Classes;
import com.night.common.entity.administration.CourseManager;
import com.night.common.entity.administration.vo.CourseManagerVo;
import com.night.common.entity.administration.vo.CourseMangerQueryVo;
import com.night.common.entity.administration.vo.TimeVo;
import com.night.common.entity.logistical.Area;
import com.night.common.entity.student.SelectCourseManagerVo;
import com.night.common.entity.student.Student;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.sql.Time;
import java.util.List;

/**
 * @ClassName: TeacherController
 * @Description: //TODO
 * @author: LZJ
 * @date: 2022/10/23-14:15
 * @version: v1.0
 */
@RestController
@RequestMapping("/api/v1/courseManager")
public class CourseManagerController {
    @Resource
    private CourseManagerService courseManagerService;

    @Resource
    private StudentFeign studentFeign;

    @Resource
    private AreaFeign areaFeign;

    /**
     * @param courseManagerId 课程id
     * @return com.night.common.entity.ResultVo<?>
     * @author Dark-Morning
     * 2022/10/25 18:40
     * 通过上课课程id查询学生集合
     **/
    @PostMapping("/getStudentIdByTeacherId/{courseManagerId}")
    public ResultVo<List<Student>> getAllStudentId(@PathVariable int courseManagerId) {
        return new ResultVo<>(courseManagerService.ListStudentsByCourseManagerId(courseManagerId));
    }

    /**
     * @param courseMangerQueryVo
     * @return com.night.common.entity.ResultVo<?>
     * @author Dark-Morning
     * 2022/10/25 19:04
     **/
    @PostMapping("/getCourseByTeacher")
    public ResultVo<?> getCourseByTeacher(@RequestBody CourseMangerQueryVo courseMangerQueryVo) {
        return new ResultVo<>(courseManagerService.listCourseManagerByTeacher(courseMangerQueryVo));
    }

    @PostMapping("/add")
    public ResultVo<String> add(@RequestBody CourseManagerVo courseManagerVo) {
        try {
            courseManagerService.judge(courseManagerVo);
        } catch (AreaConflictException e) {
            e.printStackTrace();
            return new ResultVo<>("教室已被占用");
        }
        return ResultVo.SUCCESS;
    }

    @PostMapping("/update")
    public ResultVo<String> update(@RequestBody CourseManagerVo courseManagerVo) {
        return ResultVo.SUCCESS;
    }

    @PostMapping("/time")
    public ResultVo<List<Time>> getTimes(@RequestBody TimeVo timeVo) {
        return new ResultVo(courseManagerService.checkTime(timeVo.getWeek(), timeVo.getTeacherId(), timeVo.getClassId()));
    }

    //通过班级id查询所有学生
    @PostMapping("/classId/{id}")
    public ResultVo<List<Student>> getStudentsByClassId(@PathVariable int id) {
        return new ResultVo(studentFeign.getStudentByClassId(id));
    }

    //多条件查询课程
    @PostMapping("/selectCourseBycondition")
    public ResultVo<PageBean<List<CourseManager>>> getCourseByCondition(@RequestBody SelectCourseManagerVo selectCourseManagerVo) {
        return new ResultVo<>(courseManagerService.getByCondition(selectCourseManagerVo));
    }

    //查询所有教室
    @PostMapping("/getArea")
    public ResultVo<List<Area>> getArea() {
        return new ResultVo(areaFeign.getAll());
    }

    //通过教师id查询教师的所有班级
    @PostMapping("/getClassByTeacherId/{teacherId}")
    public ResultVo<List<Classes>> getClassByTeacherId(@PathVariable int teacherId) {
        return new ResultVo<>(courseManagerService.getClassByTeacherId(teacherId));
    }
}
